<?php
class mysql{
	
	private $database_service;
	private $database_user;
	private $database_password;
	private $database_name;
	private $database_sql;
	private $database_rs;
	private $database_data=array();
	private $resource;
	public function __construct(){
		$this->database_service="localhost";
		$this->database_user="root";
		$this->database_password="1";
		$this->database_name="moto";
		
		
		//1、连接数据库
		$this->resource=mysql_connect($this->database_service,$this->database_user,$this->database_password);
		//连接失败
		if(!$this->resource){
			echo "connect failed"."<br/>";
			echo "error:".mysql_error()."<br/>";
			die();
		}
		mysql_query("set names 'utf8'");
		//2、选择数据库
		mysql_select_db($this->database_name,$this->resource);
		if(mysql_errno()){
			echo "数据库选择失败".mysql_errno();
			die();
		}
	}
	
	public function query($sql){
		
		$this->database_rs=mysql_query($sql,$this->resource);
		if($this->database_rs){
		while($arr=mysql_fetch_assoc($this->database_rs)){
			$this->database_data[]=$arr;
		}
		}
		return $this->database_data;
	}
	public function update($sql){
		return $this->database_rs=mysql_query($sql,$this->resource);
	}
	public function inser($sql){
		return $this->database_rs=mysql_query($sql,$this->resource);
	}
	public function delete($sql){
		return $this->database_rs=mysql_query($sql,$this->resource);
	}
	public function close(){
		//关闭数据库
	}
}
?>